
global !p

import vim

def gen_code_raw_github_path():
	git = "https://raw.githubusercontent.com/qrsforever/code_blog_post/master"
	path = vim.eval('expand("%:p")') or ""
	if not path:
		return git
	else:
		return git + re.match(r'.*/source/_posts(/.*)', path).groups()[0]

def gen_asset_raw_github_path():
	git = "https://raw.githubusercontent.com/qrsforever/assets_blog_post/master"
	dir = vim.eval('expand("%:p:h")') or ""
	if not dir:
		return git
	else:
		return git + re.match(r'.*/source/_posts(/.*)', dir).groups()[0] + "/"

def gen_code_raw_github_path():
	git = "https://gitee.com/lidongai/code_blog_post/raw/master"
	path = vim.eval('expand("%:p")') or ""
	if not path:
		return git
	else:
		return git + re.match(r'.*/source/_posts(/.*)', path).groups()[0]

def gen_asset_raw_gitee_path():
	git = "https://gitee.com/lidongai/assets_blog_post/raw/master"
	dir = vim.eval('expand("%:p:h")') or ""
	if not dir:
		return git
	else:
		return git + re.match(r'.*/source/_posts(/.*)', dir).groups()[0] + "/"

endglobal

snippet xhead "mark down head info" b
---

title: `!p snip.rv = snip.basename`$1

date: `date +"%Y-%m-%d %H:%M"`
tags: [$2]
categories: [$3]

---
$0
endsnippet

snippet xmore "<!-- more -->" b
<!-- more -->
endsnippet

snippet xxcenter "center DIV" b
<div align='center'>$0</div>
endsnippet

snippet xxjump "span anchor"
<span id="${1:id}"></span>
endsnippet

snippet xxline
-----------------------------------------------------------------
$0
endsnippet

snippet xxcodepandoc "```codeblock```"
\`\`\`{.${0:lang}${1: .numberLines startFrom="1"}}

\`\`\`
endsnippet

snippet xxgraph "```graphviz```"
\`\`\`{.graph ${1:.center${2: caption="${3}"}${4: fileName="${5}"}}${6: latex="true"${7: resolution="${8:1080}"${9: desity="${10:100}"}}}}
digraph G {
    graph [splines=ortho, rankdir=LR, nodesep=1];
    edge  [style=solid];
    node  [shape=circle, label=""];
    subgraph cluster_0 {
        grpah [];
        edge  [];
        node  [];
    }
}
\`\`\`
endsnippet

snippet xxcodehexo "{% codeblock %}"
{% codeblock ${1:title}${2: highlight:true${3: lang:${4:py}}${5: http:// ${6:link text}} ${7:line_number:true first_line:${8:1}}} %}
$0
{% endcodeblock %}
endsnippet

snippet xxblockhexo "{% blockquote %}"
{% blockquote ${1:${2:author}${3:, source}} ${4:${5:link} ${6:title}} %}
$0
{% endblockquote %}
endsnippet

snippet xxnb "{% asset_jupyter %}"
{% asset_jupyter python3 notebook/${1:`!p snip.rv = snip.basename`.ipynb} ${1:height} %}
$0
endsnippet

snippet xxpost_link "{% post_link %}"
{% post_link ${1:filepath} ${2:[optional text]} %}
endsnippet

snippet xxasset_img "{% asset_img %} for current dir"
{% asset_img ${1:slug} ${2:[title]} %}
endsnippet

snippet xxtable "table"
| ${1:colname} | ${2:colname} |
|:----:|:----:|
| ${3:value} | ${4:value} |
endsnippet

snippet xxunnum "div unnumbered"
<div class='unnumbered'>
$0
</div
endsnippet

snippet xxemoji "hexo emoji"
{% emoji_hj ${1:src} ${2:,[className]} %}
endsnippet

snippet xxalert "div alert info"
<div class="alert alert-info"><p>
$0
</p></div>
endsnippet

snippet xxalign "begin align"
\begin{align*}

\end{align*}
endsnippet

snippet "xxbeg( (\S+))?" "begin{} / end{}" br
\begin{${1:`!p
snip.rv = match.group(2) if match.group(1) is not None else "align*"`}}
$2 &= \\
\end{$1}$0
endsnippet

snippet xxgitcode "githubusercontent raw file"
[RAWCODE](`!p snip.rv = gen_code_raw_github_path()`)
endsnippet

snippet xxgitimg "githubusercontent asset image"
![${1:title}](`!p snip.rv = gen_asset_raw_github_path()`${0:pic.jpg})${2:{.center ${3:${4:width=${5:100%} ${6:height=${7:100px}}}}}}
endsnippet

snippet xxgiteecode "gitee code raw file"
[RAWCODE](`!p snip.rv = gen_code_raw_github_path()`)
endsnippet

snippet xxgiteeimg "gitee asset image"
![${1:title}](`!p snip.rv = gen_asset_raw_gitee_path()`${0:pic.jpg})${2:{.center ${3:${4:width=${5:100%} ${6:height=${7:100px}}}}}}
endsnippet

snippet xxdataset "baidu cloud disk"
[百度云盘Datasets](https://pan.baidu.com/s/1gAFZ9gSf4pHJBt5W6_PgPQ "提取码: gxk4")
endsnippet
